<template>
  <view class="page container">
    <u-form
      :model="basicForm"
      :rules="rules"
      labelPosition="top"
      ref="form"
      labelWidth="auto"
      :labelStyle="{
      	fontSize: '14px',
      	color: '#B2B2B2',
      	lineHight: '20px'
      }">
      <view class="basic-style">
				<u-form-item label="税率(%)" prop="taxRate">
					<h-dict-select
						style="width: 100%"
						disabled
						v-model="basicForm.taxRate" 
						placeholder="请选择税率" 
						dictName="contract_rate_type"
						border="surround"
						suffixIcon="arrow-down-fill"
					></h-dict-select>
				</u-form-item>
				<u-form-item label="应开票金额(元)" prop="shouldInvoiceAmount">
					<u--input v-model="basicForm.shouldInvoiceAmount" placeholder="请输入应开票金额" disabled></u--input>
				</u-form-item>
				<u-form-item label="已开票金额(元)" prop="onInvoiceAmount">
				  <u--input v-model="basicForm.onInvoiceAmount" placeholder="请输入已开票金额" disabled></u--input>
				</u-form-item>
				<u-form-item label="开票金额(元)" prop="invoiceAmount" required>
					<h-money-input
						placeholder="请输入开票金额"
						:isMinus="false"
						v-model="basicForm.invoiceAmount"
						:max="isCancel=='0'?((basicForm.shouldInvoiceAmount && (basicForm.onInvoiceAmount || basicForm.onInvoiceAmount==0) )?(Number(basicForm.shouldInvoiceAmount-basicForm.onInvoiceAmount)): 99999999):0"
						:min="isCancel=='0'?0:basicForm.shouldInvoiceAmount?(0-basicForm.shouldInvoiceAmount):-99999999"
					></h-money-input>
				</u-form-item>
      </view>
      <view class="space-x-1 mt-1" style="display: flex">
        <u-button type="primary" text="保存" :loading="loading" @click="onSubmit"></u-button>
        <u-button type="primary" text="关闭" :loading="loading" @click="onClose"></u-button>
      </view>
    </u-form>
  </view>
</template>

<script>
export default {
  name: 'RateForm',
  props: {
    teamId: {
      type: [String, Number],
      default: '',
      required: false
    },
    companyId: {
      type: [String, Number],
      default: '',
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
    datailDisabled: {
      type: Boolean,
      default: false,
    },
    index: {
      type: Number,
      default: null,
    },
		// 开票是否作废
		isCancel:{
			type: String,
			default: '',
			required: false
		}
  },
  data() {
    return {
      loading: false,
      basicForm: {
        amount: '',
        taxation: '',
        untaxedAmount: '',
				remark: ''
      },
      rules: {
        invoiceAmount: [
          {
            required: true,
            message: '请输入开票金额!',
            trigger: ['blur', 'change'],
          },
        ],
      },
    }
  },
  created() {},
  methods: {
    reset() {
      this.$refs.form.resetFields()
    },
    async onSubmit() {
      await this.$refs.form.validate()
			if(this.loading) return
			this.loading = true
      if (!this.index) {
        this.$emit('submit', [{
          id: parseInt(Math.random() * 1000000000000),
          ...this.basicForm,
        }, this.index])
      } else {
        this.$emit('submit', [this.basicForm, this.index])
      }
    },
    onClose() {
			this.loading = false
      this.$emit('close')
    },
  },
}
</script>

<style scoped></style>
